package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.IUserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.util.DaoFACTORY;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询所有业务组件
 */
public class FindAllService implements Servlet{
//    用户持久组件
    private IUserDao dao = (IUserDao) DaoFACTORY.getDao("IUserDao");
    public void service (Request req, Response resp){
        List<UserBean> list = dao.findAll();
        String str = "<table border='1' width='80%'>";
        str+="<thead><tr><th>用户名</th><th>密码</th><th>生日</th><th>等级</th><th>操作</th></tr></thead>";
        str+="<tbody>";
        for (UserBean user : list){
            str += "<tr><td>"+user.getName()+"</td>" +
                    "<td>"+ user.getPassword()+"</td>" +
                    "<td>"+ user.getDate()+"</td>" +
                    "<td><a href='del?id="+user.getId()+"'>删除</a></td>"+
                    "<td><a href='findById?id="+user.getId()+"'>修改</a></td></tr>?";

        }
        str+="</tbody></table>";
        resp.sendMessage(str);
    }

}
